﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using HA.ModFlow.Domain.DomainLayer;

namespace HA.ModFlow.Controls
{
    public class PCWellCollection
    {
        public PCWellCollection(ModFlowData mfData)
        {
            this._mfData = mfData;

            foreach (Well well in mfData.SourceSinks.Wells.InnerList)
            {
                this._wells.Add((Well)well.Clone());
            }

            this._periodsCount = mfData.StressPeriods.InnerList.Count;

            this._timePoint = new double[this._periodsCount + 1];
            this._timePoint[0] = 0.0;
            for (int i = 1; i <= this._periodsCount; i++)
            {
                this._timePoint[i] = this._timePoint[i - 1] + mfData.StressPeriods.InnerList[i - 1].PERLEN;
            }

        }

        public PCWellCollection(ModFlowData mfData, List<int> cellsIndex)
        {
            this._mfData = mfData;

            foreach (int index in cellsIndex)
            {
                foreach (Well well in mfData.SourceSinks.Wells.GetWell(index))

                this._wells.Add((Well)well.Clone());
            }

            this._periodsCount = mfData.StressPeriods.InnerList.Count;

            this._timePoint = new double[this._periodsCount + 1];
            this._timePoint[0] = 0.0;
            for (int i = 1; i <= this._periodsCount; i++)
            {
                this._timePoint[i] = this._timePoint[i - 1] + mfData.StressPeriods.InnerList[i - 1].PERLEN;
            }
        }

        ModFlowData _mfData;

        ObservableCollection<Well> _wells = new ObservableCollection<Well>();

        public ObservableCollection<Well> Wells
        {
            get { return _wells; }
            set { _wells = value; }
        }


       
        int _periodsCount;

        public int PeriodsCount
        {
            get { return _periodsCount; }
        }

        double[] _timePoint;

        public double[] TimePoint
        {
            get { return _timePoint; }

        }

        /// <summary>
        /// 将数据保存回数据内存
        /// </summary>
        public void ConfirmToDataCenter()
        {
            this._mfData.SourceSinks.Wells.SetWells(this._wells.ToList());
        }
    
    }
   
}
